package org.onionframework.faces.converter;

import java.util.Date;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.DateTimeConverter;
import javax.faces.convert.FacesConverter;

@FacesConverter("onion.faces.EndOfDateConverter")
public class EndOfDateConverter extends DateTimeConverter {

	@Override
	public Object getAsObject(FacesContext context, UIComponent component,
			String value) {
		Date date = (Date)super.getAsObject(context, component, value);
		
		if(date == null)
			return null;
		else
			return new Date(date.getTime() + 24 * 60 * 60 * 1000 -1);
	}

	@Override
	public String getAsString(FacesContext context, UIComponent component,
			Object value) {
		return super.getAsString(context, component, value);
	}

}
